package cn.yerly.sakura.web.controller.api;

import javax.annotation.Resource;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import cn.yerly.sakura.core.entity.ArcResponse;
import cn.yerly.sakura.dao.model.User;
import cn.yerly.sakura.service.UserService;

/**
 * ProductAPI : 商品数据api
 */
@RestController
@RequestMapping("/user")
public class UserAPI {

	@Resource
	private UserService userService;

	
	@RequestMapping(method = RequestMethod.POST)
	@ResponseBody
	public ArcResponse<User> addProduct(@RequestBody User user) {

		userService.addModel(user);

		// 包装返回的数据
		return new ArcResponse<User>(HttpStatus.CREATED.value(), "创建成功",
				user);
	}

	
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	@ResponseBody
	public ArcResponse<User> product(@PathVariable("id") Long id) {

		User user= userService.getModelById(id);

		return new ArcResponse<User>(HttpStatus.OK.value(), "查询成功", user);
	}

}
